SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
GO

PRINT '---- tblTeamMembers'

PRINT '-- Table title'
INSERT tblUFGTableTitles (utt_Tablename, utt_Languagename, utt_Title, utt_Description)
VALUES ('tblTeamMembers','Nederlands','Teamleden','Teamleden gegevens')

PRINT '-- Column titles'

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblTeamMembers','tmm_Clubname','Nederlands','Clubnaam','Kies een Clubnaam')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblTeamMembers','tmm_Season','Nederlands','Seizoen','Kies een seizoen')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblTeamMembers','tmm_TeamName','Nederlands','Team','Kies een team')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblTeamMembers','tmm_PersonID','Nederlands','Lid naam','Kies een Lid')

INSERT tblUFGColumnTitles
(uct_TableName,uct_ColumnName,uct_Languagename,uct_Title,uct_SubTitle)
VALUES
('tblTeamMembers','tmm_Suspension','Nederlands','Geschorst','Speler geschorst')

PRINT '-- Panels'
PRINT '-- Column rights'

UPDATE tblUFGForeignKeyColumns
SET ufc_AdditionalWhere = 'dbo.fnGetClubnameByUser(@UFGUsername) IN (prs_FamilyClubName, ''*'') AND NOT prs_State = ''Geroyeerd'''
WHERE ufc_ForeignKeyName = 'FK_tmm_PersonID'
AND ufc_TableName = 'tblTeamMembers'
AND ufc_ColumnName = 'tmm_PersonID'
AND ufc_ReferenceTableName = 'tblPersons'
AND ufc_ReferenceColumnName = 'prs_ID'

UPDATE tblUFGForeignKeyColumns
SET ufc_AdditionalWhere = 'dbo.fnGetClubnameByUser(@UFGUsername) IN (tea_Clubname, ''*'')'
WHERE ufc_ForeignKeyName = 'FK_tmm_Clubname_tmm_TeamName'
AND ufc_TableName = 'tblTeamMembers'
AND ufc_ColumnName = 'tmm_Clubname'
AND ufc_ReferenceTableName = 'tblTeams'
AND ufc_ReferenceColumnName = 'tea_Clubname'

PRINT '-- Row Rights'

INSERT tblUFGRowRights
(urr_TableName,urr_RoleName,urr_SQLSelectExpression,urr_SQLInsertExpression,urr_SQLUpdateExpression,urr_SQLDeleteExpression)
SELECT 'tblTeamMembers',urr_Rolename,'tmm_Clubname = dbo.fnGetClubnameByUser(@UFGUsername)',null,'tmm_Clubname = dbo.fnGetClubnameByUser(@UFGUsername)','tmm_Clubname = dbo.fnGetClubnameByUser(@UFGUsername)'
FROM tblUFGRoles
WHERE urr_RoleName LIKE '%Club'

PRINT '-- Display'

